<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@include file="../header.jsp"%>
<%
	Object pah = request.getAttribute("picpath");
	String phoUrl =  "album/IMG_0140.JPG";
	if (pah != null) {
		phoUrl = String.valueOf(pah);
	}
%>
<script type="text/javascript">
	$(function() {
		$("input[type='file']").change(function(evt) {
			var files = evt.target.files;
			for ( var i = 0, f; f = files[i]; i++) {
				if (!f.type.match('image.*')) {
					continue;
				}
				var reader = new FileReader();
				reader.onload = (function(theFile) {
					return function(e) {
						$("#list img").attr("src", e.target.result);
					};
				})(f);
				reader.readAsDataURL(f);
			}
		});
	});
</script>

<form id="form1" name="form1" method="post"
	action="<%=basePath%>album.do?upload_photo&type=0"
	enctype="multipart/form-data">
		<table>
			<tr>
				<td colspan="2"><div id="list" align="center">
						<img style="width: 350px;height:420px" src="<%=basePath%><%=phoUrl%>">
					</div>
				</td>
				<td>照片：<input type="file" name="photoUrl" title="选择照片"
								size="20">
				</td>
				<td colspan="2"><input id="submit" type="submit" value="上传" />
				<input id="reset" type="reset" value="重置" /></td>
			</tr>
			</table>
	</form>	
	<form id="form1" name="form1" method="post" action="<%=basePath%>album.do?save_photo">					
	<div align="center">
		<table>
			<tr>
				<td>相册： <select name="album" id="album">
									<%
										List albums = (List) request.getSession().getAttribute("albums");
										if (albums != null) {
											for (int i = 0; i < albums.size(); i++) {
												Album c = (Album) albums.get(i);
									%>
									<option value="<%=c.getId()%>"><%=c.getName()%></option>
									<%
										}
										}
									%>
							</select><a href="<%=basePath%>views/album/addAlbum.jsp">新建相册</a></td>
						</tr>
						<tr>
							<td><textarea name="picName" cols="50" rows="1" id="picName">请输入照片名称</textarea>
							</td>
						</tr>
						<tr>
							<td><textarea name="picComment" cols="50" rows="4"
									id="picComment">请输入照片描述</textarea>
							</td>
						</tr>
						<tr>
				<td colspan="2">
				<input id="picpath" name="picpath"  type="hidden" value="<%=phoUrl%>" />
				<input id="submit" type="submit" value="保存" />
				</td>
			</tr>

		</table>
	</div>
</form>
<%@include file="../footer.jsp"%>